#region Using directives
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using webapp4U.BOL;
#endregion


namespace webapp4U.DAL
{
	 public class HitCounterDAL : BaseDAL
	 {
         #region ObjIDataReader

         /// <summary>
         /// Returns a new Products instance filled with the DataReader's current record data 
         /// </summary>
         private HitCounter GetHitCounterFromReader(IDataReader dr)
         {
             HitCounter obj = new HitCounter();
             obj.HitCounterID = (dr["HitCounterID"] is DBNull) ? Int32.MinValue : (Int32)dr["HitCounterID"];
             obj.PageName = (dr["PageName"] is DBNull) ? String.Empty : (String)dr["PageName"];
             obj.PageUrl = (dr["PageUrl"] is DBNull) ? String.Empty : (String)dr["PageUrl"];
             obj.Counter = (dr["Counter"] is DBNull) ? Int32.MinValue : Int32.Parse(dr["Counter"].ToString());
             return obj;
         }
         #endregion


	     /// <summary>
	     /// Returns a collection of Products with the data read from the input DataReader
	     /// </summary>
	     private List<HitCounter> GetHitCounterCollectionFromReader(IDataReader dr)
	     {
		     List<HitCounter> obj = new List<HitCounter>();
		     while(dr.Read())
			     obj.Add(GetHitCounterFromReader(dr));
		     return obj;
	     }

         
         public bool Save(HitCounter obj)
         {
             using (SqlConnection myConn = GetConnectionString())
             {
                 SqlCommand myCommand = new SqlCommand("Job_HitCounter_Update", myConn);
                 myCommand.CommandType = CommandType.StoredProcedure;
                 myCommand.Parameters.Add("@PageUrl", SqlDbType.NVarChar).Value = obj.PageUrl;                 
                 int ret = myCommand.ExecuteNonQuery();
                 return (ret == 1);
             }
         }


	     
	     //Get All HitCounter
         public List<HitCounter> GetHitCouterAll()
	     {
             using (SqlConnection myConn = GetConnectionString())
		     {
                SqlCommand myCommand = new SqlCommand("Job_HitCounter_GetAll", myConn); 
		        myCommand.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = myCommand.ExecuteReader();
                return GetHitCounterCollectionFromReader(dr);
		     }
	     }        
	 }
}
